package com.ljfresh.customer.controller;

import com.ljfresh.customer.page.PageObject;
import com.ljfresh.customer.page.PageResult;
import com.ljfresh.customer.pojo.Store;
import com.ljfresh.customer.result.StoreListResult;
import com.ljfresh.customer.sercice.StoreService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: Lucifer
 * @time: 2020/4/6-10:37
 */
@Api(value = "门店",tags = "门店模块接口")
@RestController
@RequestMapping("/store")
public class StoreController {

    @Resource
    private StoreService storeService;

    @GetMapping("/findStore")
    @ApiOperation("查找门店接口")
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数错误"),
            @ApiResponse(code = 202001,message = "暂无门店~"),
            @ApiResponse(code = 205002,message = "查询失败~")
    })
    public StoreListResult findStore(@RequestParam(value = "name",required = false) String name,
                                        @RequestParam(value = "pageNo") Integer pageNo,
                                     @RequestParam(value = "pageSize") Integer pageSize){
        StoreListResult storeListResult = null;
        try {
            Map map = new HashMap();
            if (name!=null && !name.equals("")){
                map.put("likeName",name);
            }
            PageObject pageObject = new PageObject((pageNo-1)*pageSize,pageSize,map);
            PageResult<Store> stores = storeService.findByPage(pageObject);
            if (stores.getTotalCount()>0){
                storeListResult = new StoreListResult(stores);
            }else{
                storeListResult = new StoreListResult(202001);
            }
            return storeListResult;
        }catch (Exception e){
            e.printStackTrace();
            storeListResult = new StoreListResult(205002);
            return storeListResult;
        }
    }
}
